package com.wwwarehouse.usercenter.fragment.share;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.common.Common;
import com.wwwarehouse.common.custom_widget.share.ShareContent;
import com.wwwarehouse.common.custom_widget.share.ShareItem;
import com.wwwarehouse.common.custom_widget.share.SharePopuwindow;
import com.wwwarehouse.common.tools.ShareUtils;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.constant.UserCenterConstant;


@Route(path = UserCenterConstant.PATH_SHARE_TEST_FRAGMWNT)
public class TestShareFragment extends BaseFragment implements View.OnClickListener {

    private Button mShareBtn;
    private Context mContext;
    private View mRootView;
    SharePopuwindow popuwindow;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.activity_test, container, false);
        mRootView.setBackgroundColor(getResources().getColor(R.color.common_color_c10_eceff3));
        return mRootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initView();
    }


    private void initView() {
        mShareBtn = (Button) mRootView.findViewById(com.wwwarehouse.common.R.id.share_btn);
        mContext  = mActivity;
        mShareBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        final int commit_tag = 1001,circle_tag = 1002,wechat_tag = 1003 , qq_tag = 1004 , qq_zone_tag = 1005 , message_tag =1006,facetoface_tag = 1007 , copy_tag = 1008;

        int i = v.getId();
        if (i == com.wwwarehouse.common.R.id.share_btn) {
            final ShareContent content = new ShareContent();
            content.setContent("我是分享的内容哦");
            content.setTitle("我是标题");
            content.setImageUrl("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=350573396,473598857&fm=26&gp=0.jpg");
            content.setUrl("http://www.baidu.com");
            content.setPhoneNum("23234141");
            content.setMessage("我是短信内容");
            content.setCopyContent("我是拷贝的内容");
            content.setShareDestname("目的名字");

            popuwindow = SharePopuwindow.getInstance(mActivity)
                    .setContent(content)
                    .addItem(com.wwwarehouse.common.R.drawable.share_pop_commit, "站内通讯", commit_tag)
                    .addItem(com.wwwarehouse.common.R.drawable.share_pop_facetoface, "面对面", facetoface_tag)
                    .addItem(com.wwwarehouse.common.R.drawable.share_pop_message, "短信", message_tag)
                    .addItem(com.wwwarehouse.common.R.drawable.share_pop_copy, "复制链接", copy_tag)

                    .addItem(com.wwwarehouse.common.R.drawable.share_pop_wechat, "微信好友", wechat_tag)
                    .addItem(com.wwwarehouse.common.R.drawable.share_pop_circle, "朋友圈", circle_tag)
                    .addItem(com.wwwarehouse.common.R.drawable.share_pop_qq, "QQ好友", qq_tag)
                    .addItem(com.wwwarehouse.common.R.drawable.share_pop_qzone, "QQ空间", circle_tag)
                    .setOnSheetItemClickListener(new SharePopuwindow.OnSheetItemClickListener() {
                        @Override
                        public void onClick(SharePopuwindow sharePopuwindow, Object tag) {
                            switch ((int) tag) {
                                case commit_tag:
                                    sharePopuwindow.hidePop();
                                    Bundle bundle = new Bundle();
                                    bundle.putParcelable("content", content);
                                    ((BaseCardDeskActivity)mContext).pushFragment(UserCenterConstant.PATH_SHARE_INVITED_OWN,bundle);
                                    break;
                                case circle_tag:
                                    sharePopuwindow.hidePop();
                                    Common.getInstance().shareWeixinMoment(mContext, "" + content.getTitle(), content.getContent(), content.getImageUrl(), content.getUrl());
                                    break;
                                case wechat_tag://微信
                                    sharePopuwindow.hidePop();
                                    Common.getInstance().shareWeixinFriend(mContext, "" + content.getTitle(), content.getContent(), content.getImageUrl().replace("https", "http"), content.getUrl());
                                    break;
                                case qq_tag://qq
                                    sharePopuwindow.hidePop();
                                    Common.getInstance().shareQQ(mContext, "" + content.getTitle(), content.getContent(), content.getImageUrl(), content.getUrl());
                                    break;
                                case qq_zone_tag://qq空间
                                    sharePopuwindow.hidePop();
                                    Common.getInstance().shareQQZone(mContext, "" + content.getTitle(), content.getContent(), content.getImageUrl(), content.getUrl());
                                    break;
                                case message_tag://短信
                                    sharePopuwindow.hidePop();
                                    ShareUtils.sendMessage(mContext,content.getPhoneNum(), content.getMessage());
                                    break;
                                case copy_tag://拷贝
                                    sharePopuwindow.hidePop();
                                    ShareUtils.copyContent(mContext,content.getCopyContent());
                                    break;
                                case facetoface_tag://维码分二享界面
                                    sharePopuwindow.hidePop();
                                    Bundle bundle2 = new Bundle();
                                    bundle2.putString("ShareMsg",content.getContent());
                                    ((BaseCardDeskActivity)mContext).pushFragment(UserCenterConstant.PATH_SHARE_QRCODE_OWN,bundle2);

                                    break;
                            }
                        }
                    })
                    .showCancleBtn(true);
            popuwindow.showPop();
            popuwindow.changeShowType(commit_tag, ShareItem.TypeState.LOADING);

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    popuwindow.changeShowType(commit_tag, ShareItem.TypeState.CONTENT);
                }
            },2000);

        }
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof TestShareFragment) {
            mActivity.setTitle("test");
        }
    }

    @Override
    public void requestDatas() {

    }
}
